package com.wys.ws_im.utils;


import cn.hutool.core.util.StrUtil;
import com.wys.ws_im.exception.FrameErrorCodeEnums;
import com.wys.ws_im.exception.IErrorCode;
import com.wys.ws_im.vo.ResultVO;

/**
 * @author wys
 * created in 23:50 2019/1/5
 */
public class ResultUtil {

    public static <T> ResultVO<T> success() {
        return success(null, null, null);
    }

    public static <T> ResultVO<T> success(String msg) {
        return success(null, msg, null);
    }

    public static <T> ResultVO<T> success(T data) {
        return success(null, null, data);
    }

    public static <T> ResultVO<T> success(Integer count) {
        return success(count, null, null);
    }

    public static <T> ResultVO<T> success(Integer count, T data) {
        return success(count, null, data);
    }

    public static <T> ResultVO<T> success(Integer count, String msg, T data) {
        ResultVO<T> resultVO = new ResultVO<>(FrameErrorCodeEnums.SUCCESS);
        resultVO.setMsg(msg);
        resultVO.setCount(count);
        resultVO.setData(data);
        return resultVO;
    }

    public static <T> ResultVO<T> failure(IErrorCode errorCode) {
        return failure(errorCode, null);
    }

    public static <T> ResultVO<T> failure(String msg) {
        return failure(null, msg);
    }

    /**
     * 返回失败的结果，调用该方法时，由于是无参的，因此返回默认的SERVER_INTERNAL_ERROR(服务器内部错误)
     */
    public static ResultVO failure() {
        return failure(FrameErrorCodeEnums.SERVER_INTERNAL_ERROR);
    }

    public static <T> ResultVO<T> failure(IErrorCode errorCode, String msg) {
        ResultVO<T> resultVO = new ResultVO<>(errorCode);
        if (StrUtil.isNotBlank(msg)) {
            resultVO.setMsg(msg);
        }
        return resultVO;
    }

}
